<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<form:form commandName="coordinate" cssClass="form-horizontal" role="form">
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="problemName">问题名称</label>
        <div class="col-sm-4">
            <input type="text" name="problemName" id="problemName" placeholder="项目名" value="${coordinate.problemName}"
                   class="form-control"/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="industryName">指标名称</label>
        <div class="col-sm-4">
            <input type="text" name="industryName" id="industryName" placeholder="指标名称"
                   value="${coordinate.industryName}"
                   class="form-control" readonly/>
        </div>
        <label class="col-sm-2 control-label no-padding-right" for="industryDate">指标时间</label>
        <div class="col-sm-4">
            <input type="text" name="industryDate" id="industryDate" placeholder="指标时间"
                   value="${coordinate.industryDate}"
                   class="form-control" readonly/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="baseInfo">基本情况</label>
        <div class="col-sm-10">
            <textarea rows="2" id="baseInfo" name="baseInfo" placeholder="基本情况"
                      class="form-control ">${coordinate.baseInfo}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="helpInfo">需协调事项</label>
        <div class="col-sm-10">
            <textarea id="helpInfo" name="helpInfo" rows="2" placeholder="需协调事项"
                      class="form-control ">${coordinate.helpInfo}</textarea>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="groupCode_edit">督查组</label>
        <div class="col-sm-4">
            <select name="groupCode" id="groupCode_edit"
                    class="form-control <%--departments--%>" <%--multiple="multiple"--%> required>
                <option value="">--请选择--</option>
                <c:forEach items="${supervisionList }" var="supervisionList">
                    <option value="${supervisionList.sysId}">${supervisionList.deptName}</option>
                </c:forEach>
            </select>
        </div>
        <label class="col-sm-2 control-label no-padding-right" for="deptId_edit">责任单位</label>
        <div class="col-sm-4">
            <select name="deptId" id="deptId_edit" class="form-control " required>
                <option value="">--请选择--</option>
                <c:forEach items="${resDepts }" var="resDepts">
                    <option value="${resDepts.sysId}">${resDepts.deptName}</option>
                </c:forEach>
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="inspectors_edit">督查组成员</label>
        <div class="col-sm-4">
            <input type="text" name="inspectors" id="inspectors_edit" class="form-control" readonly required/>
        </div>
        <label class="col-sm-2 control-label no-padding-right" for="resUser_edit">责任人</label>
        <div class="col-sm-4">
            <input type="text" name="resUser" id="resUser_edit" class="form-control" readonly required/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="phones_edit">督查成员手机号</label>
        <div class="col-sm-4">
            <input type="text" name="phones" id="phones_edit" class="form-control" readonly required/>
        </div>
        <label class="col-sm-2 control-label no-padding-right" for="resPhone_edit">责任人手机号</label>
        <div class="col-sm-4">
            <input type="text" name="resPhone" id="resPhone_edit" class="form-control" readonly required/>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="userName">上报人</label>
        <div class="col-sm-4">
            <input type="text" name="userName" id="userName" class="form-control" value="${coordinate.userName}"
                   readonly/>
        </div>
        <label class="col-sm-2 control-label no-padding-right" for="source">来源</label>
        <div class="col-sm-4">
            <input type="text" name="source" id="source" class="form-control" value="${coordinate.source}" required/>
        </div>
    </div>
    <input type="text" name="userId" id="userId_edit" hidden />
    <input type="text" id="sysId" value="${coordinate.sysId}" hidden>
    <form:hidden path="sysId"/>
    <%--<form:hidden path="maxVal"/>
    <form:hidden path="minVal"/> --%>
</form:form>
<script>

    $(function () {

        //责任单位
        var deptIdSelected = '${coordinate.deptId}';
        //jq选中select
        $("#deptId_edit option[value = '" + deptIdSelected + "']").attr("selected", true);
        console.log(deptIdSelected)
        if (deptIdSelected != null) {
            var deptId = $("#deptId_edit").val();
            $.ajax({
                url: "/jobmanages/queryResUserByDeptId",
                type: "GET",
                dataType: "json", //返回数据形式为json
                contentType: 'application/json;charset=UTF-8',
                async: true,
                data: {"deptId": deptId},
                success: function (res) {
                    debugger;
                    if (res != null) {
                        $("#resUser_edit").val(res.name);
                        $("#resPhone_edit").val(res.mobile);
                        $("#userId_edit").val(res.sysId);
                    }
                }
            });
        }

        $("#deptId_edit").change(function () {
            var deptId = $("#deptId_edit").val();
            $.ajax({
                url: "/jobmanages/queryResUserByDeptId",
                type: "GET",
                dataType: "json", //返回数据形式为json
                contentType: 'application/json;charset=UTF-8',
                async: true,
                data: {"deptId": deptId},
                success: function (res) {
                    if (res != null) {
                        $("#resUser_edit").val(res.name);
                        $("#resPhone_edit").val(res.mobile);
                        $("#userId_edit").val(res.sysId);
                    }
                }
            });
        });

        $("#groupCode_edit").change(function () {
            var groupCode = $("#groupCode_edit").val();
            $.ajax({
                url: "/jobmanages/querySupervisionUserByDeptId",
                type: "GET",
                dataType: "json", //返回数据形式为json
                contentType: 'application/json;charset=UTF-8',
                async: true,
                data: {"deptId": groupCode},
                success: function (res) {
                    if (res != null) {
                        $("#inspectors_edit").val(res.name);
                        $("#phones_edit").val(res.mobile);
                    }
                }
            });
        });

        //督查组
        var groupCodeSelected = '${coordinate.groupCode}';
        //jq选中select
        $("#groupCode_edit option[value = '" + groupCodeSelected + "']").attr("selected", true);
        console.log(groupCodeSelected)
        if (groupCodeSelected != null) {
            var groupCode = $("#groupCode_edit").val();
            $.ajax({
                url: "/jobmanages/querySupervisionUserByDeptId",
                type: "GET",
                dataType: "json", //返回数据形式为json
                contentType: 'application/json;charset=UTF-8',
                async: true,
                data: {"deptId": groupCode},
                success: function (res) {
                    if (res != null) {
                        $("#inspectors_edit").val(res.name);
                        $("#phones_edit").val(res.mobile);
                    }
                }
            });
        }
    })

</script>
